package com.xx.ems.model;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

/**
 * @author xxx
 * @date 2014-2-25
 * @version 1.0
 * 描述: 动作表
 */
@Entity
public class Action {
	/**
	 * 描述：主键
	 */
	private Integer aid;
	/**
	 * 描述：动作名称
	 */
	private String action_name;
	/**
	 * 描述：父亲节点id
	 */
	private Integer parent_id;
	/**
	 * 描述：动作地址
	 */
	private String action_url;
	/**
	 * 描述：备注
	 */
	private String comment;
	/**
	 * 描述：角色表关联对象
	 */
	private Set<Roles> roles = new HashSet<Roles>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="aid",unique=true,nullable=false)
	public Integer getAid() {
		return aid;
	}
	public void setAid(Integer aid) {
		this.aid = aid;
	}
	@Column(name="action_name",length=30,nullable=false)
	public String getAction_name() {
		return action_name;
	}
	public void setAction_name(String action_name) {
		this.action_name = action_name;
	}
	@Column(name="parent_id",nullable=false)
	public Integer getParent_id() {
		return parent_id;
	}
	public void setParent_id(Integer parent_id) {
		this.parent_id = parent_id;
	}
	@Column(name="action_url",length=255)
	public String getAction_url() {
		return action_url;
	}
	public void setAction_url(String action_url) {
		this.action_url = action_url;
	}
	@Column(name="comment",length=255)
	public String getComment() {
		return comment;
	}
	public void setComment(String comment) {
		this.comment = comment;
	}
	@ManyToMany(targetEntity=Roles.class,cascade=CascadeType.ALL)
	@JoinTable(name="roles_action",
		joinColumns={@JoinColumn(name="fk_aid")},
		inverseJoinColumns={@JoinColumn(name="fk_rid")})
	public Set<Roles> getRoles() {
		return roles;
	}
	public void setRoles(Set<Roles> roles) {
		this.roles = roles;
	}
	/**
	 * 描述: 将实体的属性及相应的值转换成Map类型(为了方便转换成json格式后前台调用) 
	 * @return
	 * @date 2014-2-27
	 */
	public Map<String, Object> toHashMap(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("aid", getAid());
		map.put("action_name", getAction_name());
		map.put("parent_id", getParent_id());
		map.put("action_url", getAction_url());
		return map;
	}
}
